package org.seefly.iprint.service.impl;

import org.seefly.iprint.entity.Helpinfo;
import org.seefly.iprint.entity.PageBean;
import org.seefly.iprint.mapper.HelpinfoMapper;
import org.seefly.iprint.service.HelpInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;



@Service
public class HelpInfoServiceImpl implements HelpInfoService {
    @Autowired
    private HelpinfoMapper mapper;
    
    
    @Override
    public void addNew(Helpinfo info) {
        Integer id = info.getId();
        if(id != null) {
            info.setUpdateTime(new Date());
            mapper.updateByPrimaryKeySelective(info);
        }else {
            info.setCreateTime(new Date());
            info.setReadCount(0);
            mapper.insert4Key(info);
        }
    }


    @Override
    public PageBean<Helpinfo> findInfoList(Integer currPage, Integer pageSize, String queryType, String key) {
        int start = (currPage -1) * pageSize;
        List<Helpinfo> list = mapper.getListByPage(start,pageSize,queryType,key);
        int count = mapper.getListCount(queryType,key);
       
        PageBean<Helpinfo> pb = new PageBean<>();
        pb.setCurrPage(currPage);
        pb.setList(list);
        pb.setPageSize(pageSize);
        pb.setTotalCount(count);
        return pb;
    }
    
    @Override
    public Helpinfo getInfoById(String id) {
        return mapper.selectByPrimaryKey(Integer.valueOf(id));
    }
    
    @Override
    public void delInfoById(Integer id) {
        mapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Helpinfo> findNewAdsInfo(int start,int size) {
        return mapper.findNewAdsInfo(start,size);
    }
    
    @Override
    public List<Helpinfo> findNewHelpInfo(int start,int size) {
        return mapper.findNewHelpInfo(start,size);
    }
}
